package com.chx.mapper;

import com.chx.annotation.AutoFill;
import com.chx.dto.ProductPageQueryDto;
import com.chx.entity.Products;
import com.chx.enumeration.OperationType;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author cp-月入过万
 * @Date 2025/5/30
 */
@Mapper
public interface ProductMapper {
    @Select("select * from products")
    List<Products> getAllProducts();

    @Insert("insert into products(product_code,product_name,category_id,supplier_id,specification,unit,purchase_price,sale_price,stock_quantity,min_stock,max_stock,description,create_time,update_time) " +
            "values " +
            "(#{productCode},#{productName},#{categoryId},#{supplierId},#{specification},#{unit},#{purchasePrice},#{salePrice},#{stockQuantity},#{minStock},#{maxStock},#{description},#{createTime},#{updateTime})")
    @AutoFill(OperationType.INSERT)
    void insert(Products products);

    @AutoFill(OperationType.UPDATE)
    void update(Products products);

    @Delete("delete from products where product_id = #{id}")
    void delete(Long id);

    @Select("select * from products where product_id = #{id}")
    Products getById(Long id);

    Page<Products> page(ProductPageQueryDto productPageQueryDto);

    @Select("select count(*) as total from products where supplier_id = #{id}")
    int getProductById(Long id);
}
